package org.example.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.WrongQuestionDao;
import org.example.entity.WrongQuestionEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WrongQuestionServiceImpl extends ServiceImpl<WrongQuestionDao, WrongQuestionEntity> implements WrongQuestionService {

    @Autowired
    private WrongQuestionDao wrongQuestionDao;

    @Override
    public void saveWrongQuestion(WrongQuestionEntity wrongQuestionEntity) {
        wrongQuestionDao.insert(wrongQuestionEntity);
    }

    @Override
    public void updateWrongQuestion(WrongQuestionEntity wrongQuestionEntity) {
        wrongQuestionDao.updateById(wrongQuestionEntity);
    }

    @Override
    public void deleteWrongQuestion(int wrongId) {
        wrongQuestionDao.deleteById(wrongId);
    }

    @Override
    public WrongQuestionEntity getWrongQuestionById(int wrongId) {
        return wrongQuestionDao.selectById(wrongId);
    }

    @Override
    public List<WrongQuestionEntity> getAllWrongQuestions() {
        return wrongQuestionDao.selectList(null);
    }

    @Override
    public List<WrongQuestionEntity> getWrongQuestionsByStudentId(int studentId) {
        QueryWrapper<WrongQuestionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("student_id", studentId);
        return wrongQuestionDao.selectList(queryWrapper);
    }
}
